﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankSystemWithCSharp.DataBase
{
    public partial class BankDataBase
    {
        private void ConfirmAccountFormat(string accountNumber)
        {
            // 检查accountNumber是纯数字
            if (!accountNumber.All(char.IsDigit))
                throw new DataBaseException(DataBaseExceptionType.InvalidAmount, "账号必须是纯数字");
        }

        private void ConfirmAccountExist(string accountNumber)
        {
            if (!accounts.ContainsKey(accountNumber))
                throw new DataBaseException(DataBaseExceptionType.AccountNotFound, "账号不存在");
        }

        private void ConfirmAccountNotExist(string accountNumber)
        {
            if (accounts.ContainsKey(accountNumber))
                throw new DataBaseException(DataBaseExceptionType.AccountAlreadyExists, "账号已存在");
        }

        private void ConfirmPasswordFormat(string password)
        {
            // 检查password是6位纯数字
            if (password.Length != 6 || !password.All(char.IsDigit))
                throw new DataBaseException(DataBaseExceptionType.InvalidPassword, "密码必须是6位纯数字");
        }

        private void ConfirmLogin()
        {
            if (loginAccount == null)
                throw new DataBaseException(DataBaseExceptionType.NotLogin, "未登录");
        }

        private void ConfirmMoneyEnough(double money)
        {
            if (loginAccount.Money < money)
                throw new DataBaseException(DataBaseExceptionType.MoneyNotEnough, "余额不足");
        }
    }
}
